﻿using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.Domain.Jocker;
using MangoMes.Commont.Domain.Products;
using MangoMes.Commont.DTOs;
using MangoMes.Commont.Infrastructures.Interfaces;
using MathNet.Numerics.Distributions;
using MediatR;

namespace MangoMes.Write.API.Applications.PurchaseStorags
{
    public class warehouseListHandler : IRequestHandler<warehouseListCommand,ResultsDTO<Stashs>>
    {
        private readonly IBateRepository<Stashs> stashs;
        private readonly ILogger<warehouseListHandler> logger;
        public warehouseListHandler(IBateRepository<Stashs> stashs, ILogger<warehouseListHandler> logger)
        {
            this.stashs = stashs;   
            this.logger = logger;
        }
        /// <summary>
        /// 仓库列表下拉框
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async  Task<ResultsDTO<Stashs>> Handle(warehouseListCommand request, CancellationToken cancellationToken)
        {
            try
            {
                DapperHelper helper = new DapperHelper();
                Stashs stash = new Stashs();
                ResultsDTO<Stashs> dto = new ResultsDTO<Stashs> { Code = 0 };
                string conn = helper.MangoMesWrite;
                string sql = "SELECT * from warehouselist";
                dto.Data = stashs.GetAll(sql, stash, conn).ToList();
                logger.LogInformation("成功");
                return dto;
            }
            catch (Exception ex)
            {
                logger.LogError("失败" + ex);
                throw;
            }
         
        }
    }
}
